package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.entity.SysDictType;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.device.domain.req.hatdevice.HatDeviceAddReq;
import com.ruoyi.device.domain.req.hatdevice.HatDeviceEditReq;
import com.ruoyi.device.domain.req.hatdevice.HatDeviceReq;
import com.ruoyi.device.domain.resp.hatdevice.HatDeviceByIdResp;
import com.ruoyi.device.domain.resp.hatdevice.HatDeviceSearchResp;
import com.ruoyi.device.service.HatDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author wy
 * @Description 安全帽管理
 * @Date 2023/11/28 17:20
 * @Version 1.0
 */
@RestController
@RequestMapping("/system/hat")
public class HatController extends BaseController {

    @Autowired
    private HatDeviceService  hatDeviceService;

    @PreAuthorize("@ss.hasPermi('system:hat:list')")
    @GetMapping("/data")
    public TableDataInfo list(HatDeviceReq  req)
    {
        startPage();
        List<HatDeviceSearchResp> list = hatDeviceService.search(req);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('system:hat:add')")
    @PostMapping
    public Boolean add(@Valid @RequestBody HatDeviceAddReq req){
        Boolean result = this.hatDeviceService.add(req);
        return result;
    }

    @PreAuthorize("@ss.hasPermi('system:hat:edit')")
    @PutMapping
    public Boolean edit(@Valid @RequestBody HatDeviceEditReq req){
        return this.hatDeviceService.edit(req);
    }


    @PreAuthorize("@ss.hasPermi('system:hat:query')")
    @GetMapping("/{id}")
    public HatDeviceByIdResp findById(@PathVariable Long id) {
        HatDeviceByIdResp byid = this.hatDeviceService.findByid(id);
        System.out.printf("======"+byid+"========================");
        return byid;
    }

    @PreAuthorize("@ss.hasPermi('system:hat:remove')")
    @DeleteMapping("/{id}")
    public Boolean delete (@PathVariable Long[] id){
        return this.hatDeviceService.updateDel(id);
    }

}
